package main

import (
	"net"
	"common"
	"log"
	"io"
	"bufio"
)

func assert(expected, actual, name string) {
	if expected != actual {
		log.Fatalf("TEST FAIL: %s\r\nexpected %s but was %s\r\n",
			name, expected, actual)
	} else {
		log.Println("TEST OK:", name)
	}
}

func readLine(reader *bufio.Reader) (s string) {
	line, isPrefix, err := reader.ReadLine()
	common.Teste(err, "main first common.ReadLine")
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		common.Teste(err, "main first common.ReadLine")
	}
	s += string(line)
	return
}

func main() {
	c, err := net.Dial("tcp", "127.0.0.1:11211")
	common.Teste(err, "main net.Dial")
	defer c.Close()
	reader := bufio.NewReader(c)

	io.WriteString(c, "set key1 0 0 4\r\ndata\r\n")
	s := readLine(reader)
	assert("STORED", s, "simple set")
}
